from django.test import TestCase

from sqtp.models import Config, Case, Step, Request


# Create your tests here.
class TestPlatform(TestCase):
    def setUp(self):
        config1 = Config.objects.create(name="config1", base_url="url1")
        config2 = Config.objects.create(name="config2", base_url="url2")
        self.case1 = Case.objects.create(config=config1, file_path="demo_case1.yaml")
        self.case2 = Case.objects.create(config=config2, file_path="demo_case2.yaml")

    def test_steps_query(self):
        step1 = Step.objects.create(belong_case=self.case1, name="step1")
        step1.linked_case = self.case2
        step1.save()

        print(Step.objects.all().first().linked_case)
        print(Step.objects.all().first().belong_case)

        print(self.case1.test_step.all().first())
        print(self.case2.linked_case.all().first())


class TestAdd(TestCase):
    def test_add(self):
        config1 = Config.objects.create(name="config1")
        config2 = Config.objects.create(name="config2")

        case1 = Case.objects.create(config=config1, file_path="/")

        step1 = Step.objects.create(name="step1", belong_case=case1)

        request = Request.objects.create(step=step1, method=1, url="/")
